package com.ewing.extranal.im;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

/**
 * IM未读消息池
 * 
 * @author tansonlam
 * @createDate 2016年4月29日
 * 
 */
public class ImMessageNotReadPool {
    private static final ConcurrentHashMap<Long, List<String>> messagePool = new ConcurrentHashMap<Long, List<String>>();

    public static Boolean addMessageId(Long imUserId, String messageId) {
        List<String> messageList = messagePool.get(imUserId);
        if (messageList != null && messageList.contains(messageId)) {
            return false;
        }
        if (messageList == null) {
            messageList = new ArrayList<String>();
            messageList.add(messageId);
            messagePool.put(imUserId, messageList);
        } else {
            messageList.add(messageId);
        }
        return true;
    }

    public static Boolean removeMessageId(Long imUserId, String messageId) {
        List<String> messageList = messagePool.get(imUserId);
        if (messageList != null && !messageList.contains(messageId)) {
            return false;
        }
        return messageList.remove(messageId);
    }

    public static List<String> get(Long imUserId) {
        return messagePool.get(imUserId);
    }

    public static Integer count(Long imUserId) {
        List<String> list = messagePool.get(imUserId);
        return list == null ? 0 : list.size();
    }

}
